#define _CRT_SECURE_NO_WARNINGS

#include "contact.h"

void menu() {
	printf("======= My Telephone Contact List =======\n");
	printf("-----------------------------------------\n");
	printf("------ 1. Add            2. delete ------\n");
	printf("------ 3. modify         4. search ------\n");
	printf("------ 5. display        6. sort   ------\n");
	printf("------ 0. save and exit            ------\n");
	printf("-----------------------------------------\n");
	printf("=========================================\n");
}

enum Option {
	SAVE_EXIT,
	ADD,
	DELET,
	MODIFY,
	SEARCH,
	DISPLAY,
	SORT
};

int main() {
	int input = 0;
	Contact con;
	initContact(&con);
	do {
		menu();
		printf("> Please choose:>");
		scanf("%d", &input);
		system("cls");
		switch (input) {
		case ADD:
			addMember(&con);
			break;
		case DELET:
			deleteMember(&con);
			break;
		case MODIFY:
			modifyMember(&con);
			break;
		case SEARCH:
			searchMember(&con);
			break;
		case DISPLAY:
			displayContact(&con);
			break;
		case SORT:
			sortContact(&con);
			break;
		case SAVE_EXIT:
			// Save contact list
			saveContact(&con);
			// Destroy contact list
			destroyContact(&con);
			printf("> System exit\n");
			break;
		default:
			printf("> Input error\n");
		}
	} while (input);
	return 0;
}